
#include "folderpermissionlabel.h"
#include <QDebug>

FolderPermissionLabel::FolderPermissionLabel(QWidget *parent)
    : QWidget(parent)
{
    // 主布局
    m_layout = new QHBoxLayout(this);
    m_layout->setContentsMargins(5, 0, 5, 0);
    m_layout->setSpacing(15);

    // 初始化状态标签
    setupStateLabels();
}

void FolderPermissionLabel::setupStateLabels()
{
    // 创建状态映射
    QVector<StateData> states = createStateIcons();

    QHBoxLayout* readLayout = new QHBoxLayout(this);
    QLabel* readPermission = new QLabel(tr("Read"));
    StateLabel* readStatelabel = new StateLabel(states, Allow, this);

    // 监听变化
    connect(readStatelabel, &StateLabel::valueChanged, [](const QVariant& value) {
        qDebug() << "Read new value:" << value;
    });
    readLayout->addWidget(readPermission);
    readLayout->addWidget(readStatelabel);
    readLayout->addStretch();

    QHBoxLayout* writeLayout = new QHBoxLayout(this);

    QLabel* writePermission = new QLabel(tr("Write"));
    StateLabel* writeStatelabel = new StateLabel(states, Deny, this);
    // 监听变化
    connect(writeStatelabel, &StateLabel::valueChanged, [](const QVariant& value) {
        qDebug() << "Write new value:" << value;
    });
    writeLayout->addWidget(writePermission);
    writeLayout->addWidget(writeStatelabel);
    writeLayout->addStretch();

    m_layout->addLayout(readLayout);
    m_layout->addLayout(writeLayout);

}

QVector<StateData> FolderPermissionLabel::createStateIcons()
{
    // 初始化状态数据
    QVector<StateData> states = {
        {Allow, QIcon("://images/allow.png"), "allow"},
        {Deny, QIcon("://images/deny.png"), "deny"},
        {NotSet, QIcon("://images/unset.png"), "not set"}
    };
    return states;
}

// 权限设置方法
//void FolderPermissionLabel::setReadPermission(PermissionState state)
//{
//    m_readLabel->setState(state, true);
//}

//void FolderPermissionLabel::setWritePermission(PermissionState state)
//{
//    m_writeLabel->setState(state, true);
//}


